package day02.Order;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/4/17
 */
public class User {
    private String name;          // 姓名
    private String address;       // 地址
    private String phoneNumber;   // 手机号
    private Order[] orders;       // 订单数组（关联Order类）

    // 构造方法
    public User(String name, String address, String phoneNumber) {
        this.name = name;
        this.address = address;
        this.phoneNumber = phoneNumber;
        this.orders = new Order[10];
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }
    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public Order[] getOrders() {
        return orders;
    }
    public void setOrders(Order[] orders) {
        this.orders = orders;
    }

    // 下单方法（关联Order类，建立用户与订单的双向关系）
    public void placeOrder(Order order) {
        for (int i = 0; i < orders.length; i++) {
            if (orders[i] == null) {
                orders[i] = order;
                System.out.println("用户 " + name + " 下单成功！订单号：" + order.getOrderNumber());
                return;
            }
        }
        System.out.println("用户 " + name + " 的订单数量已达上限！");
    }
}
